<template>
  <j-modal
    title="物料退款审核"
    :width="500"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol">
      <a-form-item label="退款审核">
        <a-select v-model="model.status" placeholder="请选择">
          <a-select-option value="1"> 审核通过 </a-select-option>
          <a-select-option value="0"> 审核不通过 </a-select-option>
        </a-select>
      </a-form-item>

      <a-form-item label="退款金额" v-if="model.status == '1'">
        <a-input v-model="model.refundAmount" />
      </a-form-item>
    </a-form-model>
  </j-modal>
</template>

<script>
import moment from 'moment'
import { httpAction, getAction, orderRefundTypeList } from '@/api/manage'
export default {
  name: 'XhdjOrderInfoModal',
  data () {
    return {
      title: '操作',
      visible: false,
      model: { refundAmount: null },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },

      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/xhdjOrderInfo/xhdjOrderInfo/add',
        edit: '/xhdjOrderInfo/xhdjOrderInfo/edit',
        examine: '/material/xhdjMaterielOrder/examine',
        orderRefundTypeList: '/material/xhdjMaterielOrder/queryRefundMoney'
      },
      outAmount: 0,
      frefundType: []
    }
  },
  created () {},
  methods: {
    add () {
      //初始化默认值
      this.edit({})
    },
    edit (record) {
      console.log(record)

      this.visible = true
      var params = {
        orderId: record.id
      }
      orderRefundTypeList(this.url.orderRefundTypeList, params).then(res => {
        console.log(res, '信息啊')
        if (res.code == 200) {
          this.model.id = res.result.orderId
          this.model.refundAmount = res.result.refundAmount
          this.outAmount = res.result.refundAmount
        }
      })
    },
    close () {
      this.$emit('close')
      this.model = {
        id: null,
        refundAmount: null
      }
      this.outAmount = null
      this.visible = false
    },
    handleOk () {
      const that = this
      if (this.model.status == 0) {
        delete this.model.refundAmount
      }
      // 触发表单验证
      that.confirmLoading = true
      let httpurl = ''
      let method = ''
      httpurl += that.url.examine
      method = 'get'

      if (that.model.status && this.outAmount < this.model.refundAmount) {
        that.confirmLoading = false
        return this.$message.error('超出最大金额!')
      } else {
        that.confirmLoading = false
      }
      getAction(httpurl, this.model, method).then(res => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
          this.close()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    handleCancel () {
      this.close()
    }
  }
}
</script>

<style lang="less" scoped></style>
